<?php 

class Controller_UrlMapper{
	
	protected $_package = '';
	
	/**
	 * @var Request
	 */
	protected $_request;
	protected $_action;
	public function __construct($package,$request = ''){
		$this->_package = $package;
		$this->_request = $request;
	}
	public function setRequest(Request $request){
		$this->_request = $request;
	}
	public function formateURL($action , $package = ''){
		
		$httpQuery = '';
		if($package)
			$httpQuery = '/'.$package ;
        
			$httpQuery = $httpQuery. '/' . $action;
      
        
        return $httpQuery;
	} 
	
	public function parseUrl(){
		
		$path = str_replace('.php','',$_SERVER ['REQUEST_URI']);
		if (strstr ( $path, '?' )) {
			$path = substr ( $path, 0, strpos ( $path, '?' ) );
		}
	
		
	
		$path = explode ( '/', trim ( $path, '/' ) );
		
	//	if(isset($path [0]) && $this->_package == $path [0])
		//	array_shift($path);
	   
		
		
		$action = array_pop($path);
		
		$this->_package = implode(DIRECTORY_SEPARATOR, $path);
	
		
		if (!$action ) {
			
			$action = 'index';
		}
		
		
		$this->_action = ucfirst($action);
		
	}
	
	/**
	 * 
	 * 返回action名称
	 * @return String
	 */
	public function getActionName(){
		
		return $this->_action.'Action';
	}
	public function getPackage(){
		return $this->_package;
	}
}